/* This file is part of SpaceSim.
 
 SpaceSim is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 SpaceSim is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with SpaceSim.  If not, see <http://www.gnu.org/licenses/>. */

#ifndef PLANET_H
#define PLANET_H

#include <vector>
#include <string>

#include "entity.h"

#define PI 3.14159265358

namespace PlanetType {
	enum Enum {
		NoType,		//0
		Rocky,		//1 rocky, composed of silicon and metals, no atmosphere
		Quartz,		//2 rocky, composed of silicon, no atmosphere / oxygen atmosphere
		Martian,	//3 rocky, composed of silicon and metals, light atmosphere
		
		Atmos,		//4 medium density atmosphere
		Ice,		//5 covered in water ice
		Water,		//6 covered in water
		Habitable,	//7 water and breathable atmosphere
		
		Venusian,	//8 dense atmosphere
		
		GasGiant,	//9 big and gassy
		
		// Stations and warp launchers
		WarpLauncher,	//10 warps inside clusters
		HubLauncher,	//11 warps between clusters
		FreeStation		//12 doesn't orbit a planet
	};
	
	std::string GetTypeString(int type);
}


class Planet : public OrbitEntity {
private:
	int MoonCount;
	float Mass;
	float StarMass;		// The mass of the star it orbits
	Planet *Parent;		// The object it orbits
	float Temperature;
	float Atmosphere;
	std::vector<Planet> Moons;
	PlanetType::Enum Type;
public:
	Planet();				// Constructors
	Planet(float _radius, float _mass, float _starmass, Planet *_parent, PlanetType::Enum _type, float _temp, float _atm);
	
	~Planet() {	// Destructor
		Moons.clear();
		Parent = NULL;
	}
	
	float GetX() {		// Getters
		return XPos;
	}
	float GetY() {
		return YPos;
	}
	float GetOrbitRadius() {
		return ORadius;
	}
	void SetOrbitRadius(float _radius);	// This is the only one of the orbit and location required, the others are calculated from this
	void SetMass(float _mass);
	float GetMass() {
		return Mass;
	}
	void SetParent(Planet* _parent) {
		Parent = _parent;
	}
	Planet* GetParent() {
		return Parent;
	}
	PlanetType::Enum GetType() {
		return Type;
	}
	void AddMoon(Planet moon) {
		moon.SetParent(this);
		moon.SetOrbitRadius(moon.GetOrbitRadius());	// update orbit data
		moon.RecalculateOrbit(Mass);
		Moons.push_back(moon);
		MoonCount++;
	}
	std::vector<Planet> GetMoons() {
		return Moons;
	}
	int GetMoonCount() {
		return MoonCount;
	}
	void Update();						// Move the planet in its orbit
	void Draw();
	void Draw(float radius);
	void DrawInfo(int number);
	void DrawStation();
};

bool IsOrbitRadiusSmaller (Planet a, Planet b);

float MakeTemperature(PlanetType::Enum, float radius, float atmosphere);

#endif